package spacewar2.shadows;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;

import spacewar2.gui.JSpacewarComponent;
import spacewar2.objects.Base;
import spacewar2.utilities.Position;

/**
 * Draw a base. The base's transparency is based on its available healing
 * energy.  The shadow is mostly based on the spacewar 1 shadow for bases.
 * 
 * @author amy
 *
 */
public class BaseShadow extends Shadow {
	Base base;
	Color teamColor;
	
	/**
	 * Make a new base shadow for a specific team
	 * @param base
	 * @param teamColor
	 */
	public BaseShadow(Base base, Color teamColor) {
		super(Base.BASE_RADIUS, Base.BASE_RADIUS);
		this.base = base;
		this.teamColor = teamColor;
	}

	/**
	 * Return the location of the base
	 */
	public Position getActualLocation() {
		return base.getPosition();
	}

	@Override
	public void draw(Graphics2D graphics) {
		float radius = Base.BASE_RADIUS;
		float diameter = Base.BASE_RADIUS * 2;

		// change the base's transparency based upon the energy level
		int alpha =  (int) (((float) base.getHealingEnergy() / base.INITIAL_BASE_ENERGY) * 255.0);
		Color energyColor = new Color(teamColor.getRed(), teamColor.getGreen(), teamColor.getBlue(), alpha);
		graphics.setColor(energyColor);
		
		graphics.fillOval((int)(drawLocation.getX() - radius), (int)(drawLocation.getY() - radius), 
					(int)diameter, (int)diameter);

		// show the healing energy level of the base
		final Font font = new Font("Arial", Font.BOLD, 12);
		graphics.setFont(font);

		String number = Integer.toString(base.getHealingEnergy());
		graphics.setPaint(JSpacewarComponent.TEXT_COLOR);
		graphics.drawString(number, (int) drawLocation.getX() + 12, (int) drawLocation.getY() + 12);
		
		// show the money collected by the team
		number = Integer.toString(base.getMoney());
		graphics.setPaint(JSpacewarComponent.TEXT_COLOR);
		graphics.drawString(number, (int) drawLocation.getX() + 12, (int) drawLocation.getY() - 12);
		
		
	}

	@Override
	public boolean isDrawable() {
		return (base.isAlive() && base.isDrawable());
	}

}
